/*
 * Author - Lukasz Baranski <barluk87@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */


//frsky hub interface
#include "frsky.h"
#include "uart.h"


int frskyDate[NUMBER_OF_MEASURMENT][2]; //

void setAltitude(int altitude){ //[m]
    
    frskyDate[0][0]=FRSKY_BARO_ALT_B;
    frskyDate[0][1]=altitude;
}

void setVspd(int speed){// [0.1 m/s]
    
    frskyDate[1][0]=FRSKY_VERT_SPEED;
    frskyDate[1][1]=speed;
}

void setTemp(int temp1, int temp2){
    
    frskyDate[2][0]=FRSKY_TEMP1;
    frskyDate[2][1]=temp1;
    
    frskyDate[3][0]=FRSKY_TEMP2;
    frskyDate[3][1]=temp2;
    
}

void setVoltage(int voltage){
    //frskyVoltage = voltage;
    frskyDate[4][0]=FRSKY_CELL_VOLT;
    frskyDate[4][1]=voltage;
}

void sendFrame(){

	sendByte(0x5E);
    unsigned char i;
    for(i=0;i<NUMBER_OF_MEASURMENT;i++){
        if(frskyDate[i][0]){
            sendByte(frskyDate[i][0]);
            sendByte((frskyDate[i][1])&0xff);
	        sendByte((frskyDate[i][1]>>8));
	        sendByte(0x5E);
        }
    }
}

void clearData(){
    unsigned char i;
    for(i=0;i<NUMBER_OF_MEASURMENT;i++){
        frskyDate[i][0]=0;
    }
}

